package cn.buk.tms.dao;

import cn.buk.tms.sc.SearchFlightOrderCriteria;
import cn.buk.tms.entity.misc.OperationLog;
import cn.buk.tms.entity.order.OrderAttachment;
import cn.buk.tms.entity.misc.PaymentMethod;
import cn.buk.tms.entity.misc.Supplier;
import cn.buk.tms.entity.order.flight.FlightRefundOrder;

import java.util.Date;
import java.util.List;

/**
 * @author yfdai
 */
public interface FlightRefundOrderDao {

  /**
   * 创建退票订单
   */
  int createFlightRefundOrder(FlightRefundOrder info);

  /**
   * 我来处理退票
   * @param orderId 退票单id
   * @return 1 - 认领成功
   *         其它 均为失败
   */
  int processFlightRefund(int enterpriseId, String username, int orderId);

  int cancelFlightRefund(int enterpriseId, String username, int id);

  int reopenFlightRefund(int enterpriseId, String username, int id);


  /**
   * 已提交退票
   */
  int submitFlightRefund(int enterpriseId, String username, int refundTicketId);

  /**
   * 修改航司实退的价格(计算的）
   */
  int setFlightRefundAirlineRefundedAmount(int enterpriseId, String username, int id, double amount);

  /**
   * 修改航司最退的价格（根据财务到账）
   */
  int setFinallyAirRefunded(int enterpriseId, String username, int id, double amount);

  /**
   * 修改退票状态为航司预退状态
   */
  int setFlightRefundAirlineRefundedStatus(int enterpriseId, String username, int id);

  int setFlightRefundPassengerRefundedAmount(int enterpriseId, String username, int id, double amount);

  int setFlightRefundPassengerRefundedStatus(int enterpriseId, String username, int id);

  List<FlightRefundOrder> searchFlightRefundOrder(int enterpriseId, SearchFlightOrderCriteria sc, List<Integer> allowedCustomerIds);

  /**
   * 获取退票单
   */
  FlightRefundOrder getFlightRefundOrderDetail(int id);

  FlightRefundOrder getFlightRefundOrderDetailByRefundOrderNo(int enterpriseId, String refundOrderNo);

  List<OperationLog> searchFlightRefundOrderHistory(int enterpriseId, int id);

  /**
   * 根据退票订单生成退票报表
   */
  List<FlightRefundOrder> searchFlightRefundByOrder(int enterpriseId, Date beginDate, Date endDate, int supplierId);

  int updateRefundOrderPrice(int enterpriseId, String username, int id, double airRefundCharge, double serviceCharge);

  int updateRefundOrderRemark(int enterpriseId, String username, int id, String remark);

  List<FlightRefundOrder> searchUnpaidOrders(int max);

  void setOrderWrittenOff(int enterpriseId, String username, int id, String remark);



  int rollbackRefundOrderStatus(int enterpriseId, String username, int orderId, final String remark);

  /**
   * 根据机票订单号来查找关联的退票单
   *
   * @param enterpriseId 企业id
   * @param orderNo      机票订单号
   */
  List<FlightRefundOrder> searchByFlightOrderNo(int enterpriseId, String orderNo);

  int updateRefundOrderTicketNo(int enterpriseId, String username, int orderId, String balCode, String tickNo);


  int appendRefundOrderLog(int enterpriseId, String username, int orderId, String remark);

  int saveRefundOrderAttachment(int enterpriseId, String username, int orderId, List<OrderAttachment> attachments);

  List<OrderAttachment> searchAttachments(int enterpriseId, int orderId);

  List<FlightRefundOrder> searchMobileIsNull(int enterpriseId);

  List<FlightRefundOrder> searchSupplierIsNull(int enterpriseId);

  void updateRefundOrderMobile(int enterpriseId, String username, int id, String mobile);

  int updateRefundOrderSupplier(int enterpriseId, String username, int id, Supplier supplier, PaymentMethod paymentMethod);

  /**
   * 查找需要进行DETR操作的退票单
   */
  List<FlightRefundOrder> searchRefundOrdersNeedRefreshDetr(int enterpriseId, int max);

  void updateRefundOrderDetrStatus(int enterpriseId, String username, int orderId, int status);

  int updateExternalOrderNo(int enterpriseId, String username, int orderId, String externalOrderNo, String remark);

  /**
   * 查找待处理的退票单
   */
  List<FlightRefundOrder> searchWaiting(int enterpriseId, Date startDate);
}
